package com.atguigu.exam;

import java.io.*;

/**
 * 先将“欢迎您来北京尚硅谷学习，高薪就业”写入到文件”hello.txt”中，再读取该文件中的内容。
 * @author xbd
 * @create 2021-05-30 22:49
 */
public class HelloTest {
    public static void main(String[] args){
        BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter("Hello.txt"));
            String str = "欢迎您来北京尚硅谷学习，高薪就业";
            bw.write(str);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(bw != null){
                try {
                    bw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        BufferedReader bf = null;
        try {
            bf = new BufferedReader(new FileReader("Hello.txt"));
            String data;
            while ((data = bf.readLine()) != null){
                System.out.println(data);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(bf != null){
                try {
                    bf.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
